{extend name="admin/base"}

{block name="content"}
<div class="layui-card">
    <div class="layui-card-header">{$row ? '编辑' : '添加'}云存储配置</div>
    <div class="layui-card-body">
        <form class="layui-form" action="" method="post">
            <input type="hidden" name="id" value="{$row.id|default=''}">
            
            <div class="layui-form-item">
                <label class="layui-form-label">存储类型</label>
                <div class="layui-input-inline">
                    <input type="text" name="type" value="{$row.type|default=$type}" readonly class="layui-input">
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">配置名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" value="{$row.name|default=''}" required lay-verify="required" placeholder="请输入配置名称" class="layui-input">
                </div>
            </div>
            
            {if $type == 'aliyun' || (isset($row) && $row.type == 'aliyun')}
            <div class="layui-form-item">
                <label class="layui-form-label">AccessKeyId</label>
                <div class="layui-input-inline">
                    <input type="text" name="accessKeyId" value="{$row.config.accessKeyId|default=''}" required lay-verify="required" placeholder="请输入AccessKeyId" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">AccessKeySecret</label>
                <div class="layui-input-inline">
                    <input type="text" name="accessKeySecret" value="{$row.config.accessKeySecret|default=''}" required lay-verify="required" placeholder="请输入AccessKeySecret" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Endpoint</label>
                <div class="layui-input-inline">
                    <input type="text" name="endpoint" value="{$row.config.endpoint|default=''}" required lay-verify="required" placeholder="例如: oss-cn-beijing.aliyuncs.com" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Bucket</label>
                <div class="layui-input-inline">
                    <input type="text" name="bucket" value="{$row.config.bucket|default=''}" required lay-verify="required" placeholder="请输入Bucket名称" class="layui-input">
                </div>
            </div>
            {/if}
            
            {if $type == 'qiniu' || (isset($row) && $row.type == 'qiniu')}
            <div class="layui-form-item">
                <label class="layui-form-label">AccessKey</label>
                <div class="layui-input-inline">
                    <input type="text" name="accessKey" value="{$row.config.accessKey|default=''}" required lay-verify="required" placeholder="请输入AccessKey" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">SecretKey</label>
                <div class="layui-input-inline">
                    <input type="text" name="secretKey" value="{$row.config.secretKey|default=''}" required lay-verify="required" placeholder="请输入SecretKey" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Bucket</label>
                <div class="layui-input-inline">
                    <input type="text" name="bucket" value="{$row.config.bucket|default=''}" required lay-verify="required" placeholder="请输入Bucket名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">存储区域</label>
                <div class="layui-input-inline">
                    <select name="zone" required lay-verify="required">
                        <option value="z0" {if (isset($row) && $row.config.zone == 'z0')}selected{/if}>华东-浙江</option>
                        <option value="z1" {if (isset($row) && $row.config.zone == 'z1')}selected{/if}>华北-北京</option>
                        <option value="z2" {if (isset($row) && $row.config.zone == 'z2')}selected{/if}>华南-广州</option>
                        <option value="na0" {if (isset($row) && $row.config.zone == 'na0')}selected{/if}>北美-北美</option>
                        <option value="as0" {if (isset($row) && $row.config.zone == 'as0')}selected{/if}>亚太-新加坡</option>
                    </select>
                </div>
            </div>
            {/if}
            
            {if $type == 'tencent' || (isset($row) && $row.type == 'tencent')}
            <div class="layui-form-item">
                <label class="layui-form-label">SecretId</label>
                <div class="layui-input-inline">
                    <input type="text" name="secretId" value="{$row.config.secretId|default=''}" required lay-verify="required" placeholder="请输入SecretId" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">SecretKey</label>
                <div class="layui-input-inline">
                    <input type="text" name="secretKey" value="{$row.config.secretKey|default=''}" required lay-verify="required" placeholder="请输入SecretKey" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">存储区域</label>
                <div class="layui-input-inline">
                    <input type="text" name="region" value="{$row.config.region|default=''}" required lay-verify="required" placeholder="例如: ap-beijing" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Bucket</label>
                <div class="layui-input-inline">
                    <input type="text" name="bucket" value="{$row.config.bucket|default=''}" required lay-verify="required" placeholder="请输入Bucket名称" class="layui-input">
                </div>
            </div>
            {/if}
            
            <div class="layui-form-item">
                <label class="layui-form-label">访问域名</label>
                <div class="layui-input-inline">
                    <input type="text" name="domain" value="{$row.domain|default=''}" placeholder="例如: https://img.example.com" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">请填写云存储绑定的域名，带http://或https://</div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">是否默认</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_default" value="1" title="是" {if (isset($row) && $row.is_default == 1) || !isset($row)}checked{/if}>
                    <input type="radio" name="is_default" value="0" title="否" {if isset($row) && $row.is_default == 0}checked{/if}>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="启用" {if (isset($row) && $row.status == 1) || !isset($row)}checked{/if}>
                    <input type="radio" name="status" value="0" title="禁用" {if isset($row) && $row.status == 0}checked{/if}>
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSubmit">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    <a href="{:url('index')}" class="layui-btn layui-btn-normal">返回</a>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="script"}
<script>
    layui.use(['form'], function(){
        var form = layui.form;
        
        // 表单提交
        form.on('submit(formSubmit)', function(data){
            $.post(location.href, data.field, function(res){
                if(res.code === 1){
                    layer.msg(res.msg, {icon: 1}, function(){
                        location.href = '{:url("index")}';
                    });
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
            return false;
        });
    });
</script>
{/block}
